<?php
namespace app\common\component\user_wallet_vip;

class UserWalletVipService {
	public function getUserWalletVipV01($user_id = null) {
		if(!$user_id) {
			$user_id = \think\Session::get('user_id');
		}

		$getUserWalletVip = UserWalletVipModel::get(['user_id' => $user_id]);

		if(!$getUserWalletVip) {

			$resultUserWalletVip = $this -> createV01([
				'user_id' => $user_id,
				'price' => 0
			]);

			if($resultUserWalletVip['code'] === 0) {
				$getUserWalletVip = $resultUserWalletVip['data']['user_wallet_vip'];
			} else {
				$getUserWalletVip = null;
			}
		}

		if($getUserWalletVip) {
			return [
				'code' => 0,
				'data' => [
					'user_wallet_vip' => $getUserWalletVip
				]
			];
		}

		return [
			'code' => -1,
			'message' => '失败'
		];
	}

	public function createV01($data) {
		$UserWalletVipModel = new UserWalletVipModel($data);

    	if($UserWalletVipModel -> save()) {
    		return [
    			'code' => 0,
    			'message' => '续费钱包创建成功',
    			'data' => [
    				'user_wallet_vip' => $UserWalletVipModel
    			]
    		];
    	}

    	return [
			'code' => -1,
			'message' => '续费钱包创建失败'
		];
	}
}
?>